using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebMaster_WebMasterLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            setLanguage();
    }
    #region functions

    private void setLanguage()
    {
        Session.Abandon();
        Session.RemoveAll();
    }

    private void CheckLogin()
    {
        try
        {
            string username = txtUserName.Text.Trim();
            string password = txtPassword.Text.Trim();
            password = GlobalClassBE.encodeMD5(password);
            GssBL.BLLogon BL = new GssBL.BLLogon();
            GssBL.BLLogon.UserRole enumRole = BL.getGroupUserLogin(username, password);
            if (enumRole == GssBL.BLLogon.UserRole.WebMaster || enumRole == GssBL.BLLogon.UserRole.WebEditor)
            {
                lblError.Visible = false;
                DataRow dr = BL.getByUsername(username);
                Session["IsLogin"] = true;
                Session["UserLogin"] = username.ToLower();
                Session["UserRole"] = enumRole;
                Session["IDLogon"] = dr["IDLogon"].ToString();
                Response.Redirect(@"Default.aspx", false);
            }
            else
            {
                lblError.Visible = true;
                Session["IsLogin"] = false;
                Session["UserLogin"] = String.Empty;
                Session["UserRole"] = String.Empty;
                Session["IDLogon"] = String.Empty;
            }
        }
        catch (Exception ex)
        {
            string error = ex.Message;
        }
    }
    #endregion functions
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        CheckLogin();
    }
}
